package com.cacho.s2b.lesson.vo;

import io.cucumber.java.Scenario;
import io.cucumber.java.an.E;
import lombok.Getter;
import lombok.Setter;
import org.apache.commons.lang3.StringUtils;

import java.util.ArrayList;
import java.util.List;

/**
 * @Description 接口请求测试关联的信息, 为了将上个接口的参数传入下个接口
 * @Author LingWei
 * @date 2023/12/31
 **/
@Getter
@Setter
public class ApiTestInfo {
    private ApiStepInfo lastStepInfo = new ApiStepInfo(); // 上一个步骤接口信息
    private List<ApiStepInfo> namedSteps = new ArrayList<>(); // 测试步骤集合
    private Scenario scenario; //测试场景
    private String envName = ""; // 测试运行环境

    public ApiTestInfo() {
    }

    public ApiStepInfo addStepRecord(String stepName) {
        ApiStepInfo step = new ApiStepInfo(stepName);
        namedSteps.add(step);
        return step;
    }
    public ApiStepInfo searchStep(String name) {
        for (ApiStepInfo step : this.namedSteps) {
            if (name.equalsIgnoreCase(step.getName())) {
                return step;
            }
        }
        return null;
    }
    public ApiStepInfo getStep(String name) throws Exception {
        ApiStepInfo step = searchStep(name);
        if (step == null){
            throw new Exception(String.format("Step <%s> not found exception.",name));
        }
        return step;
    }
}
